/**
 *
 * @param sourceArr 源数组
 * @param mergeArr  合并数组
 * @param key       比对 key
 * @returns         合并结果
 */
export function mergeByKey<T extends object, T2 extends object>(sourceArr: T[], mergeArr: T2[],
  key: Extract<keyof T, keyof T2> = 'key' as Extract<keyof T, keyof T2>) : (T & T2)[] {
  return sourceArr.map(item => {
    const mergeItem = mergeArr.find(obj => item[key] as never === obj[key] as never);
    return Object.assign(item, mergeItem)
  })
}
